package com.ruoyi.web.controller.bus.controller;

import com.ruoyi.bus.domain.BusWarningRecord;
import com.ruoyi.bus.service.IBusWarningRecordService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预警记录Controller
 * 
 * @author ruoyi
 * @date 2021-09-15
 */
@Controller
@RequestMapping("/bus/record")
public class BusWarningRecordController extends BaseController
{
    private String prefix = "bus/record";

    @Autowired
    private IBusWarningRecordService busWarningRecordService;

    @RequiresPermissions("bus:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询预警记录列表
     */
    @RequiresPermissions("bus:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusWarningRecord busWarningRecord)
    {
        startPage();
        List<BusWarningRecord> list = busWarningRecordService.selectBusWarningRecordList(busWarningRecord);
        return getDataTable(list);
    }

    /**
     * 导出预警记录列表
     */
    @RequiresPermissions("bus:record:export")
    @Log(title = "预警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusWarningRecord busWarningRecord)
    {
        List<BusWarningRecord> list = busWarningRecordService.selectBusWarningRecordList(busWarningRecord);
        ExcelUtil<BusWarningRecord> util = new ExcelUtil<BusWarningRecord>(BusWarningRecord.class);
        return util.exportExcel(list, "预警记录数据");
    }

    /**
     * 新增预警记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存预警记录
     */
    @RequiresPermissions("bus:record:add")
    @Log(title = "预警记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusWarningRecord busWarningRecord)
    {
        return toAjax(busWarningRecordService.insertBusWarningRecord(busWarningRecord));
    }

    /**
     * 修改预警记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BusWarningRecord busWarningRecord = busWarningRecordService.selectBusWarningRecordById(id);
        mmap.put("busWarningRecord", busWarningRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存预警记录
     */
    @RequiresPermissions("bus:record:edit")
    @Log(title = "预警记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusWarningRecord busWarningRecord)
    {
        return toAjax(busWarningRecordService.updateBusWarningRecord(busWarningRecord));
    }

    /**
     * 删除预警记录
     */
    @RequiresPermissions("bus:record:remove")
    @Log(title = "预警记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(busWarningRecordService.deleteBusWarningRecordByIds(ids));
    }
}
